//
//  UIBarButtonItem+Extensions.swift
//  新浪微博
//
//  Created by huami on 2019/10/15.
//  Copyright © 2019 huami. All rights reserved.
//

import UIKit

extension UIBarButtonItem {
    
    ///  创建UIBarButtonItem
    /// - Parameter title: title
    /// - Parameter fontSize: fontSize 默认16
    /// - Parameter target: target
    /// - Parameter action: action
    /// - returns UIBarButtonItem
    convenience init(title: String, fontSize: CGFloat = 16,target:Any?, action: Selector, isBack:Bool = false) {
        let btn: UIButton = UIButton.cz_textButton(title, fontSize: fontSize, normalColor:.darkGray, highlightedColor:.orange)
        
        if isBack {
            let imageName = "navigationbar_back_withtext"
            btn.setImage(UIImage.init(named: imageName), for: .normal)
            btn.setImage(UIImage.init(named: imageName + "_highlighted"), for: .highlighted)
            
            btn.sizeToFit()
        }
        
        btn.addTarget(target, action: action, for: .touchUpInside)
        
        // 实例化 UIBarButtonItem
        self.init(customView:btn)
    }
}
